import type { PageParam, PageResult } from '@vben/request';

import { requestClient } from '#/api/request';

export namespace CmtContentCommentApi {
  export interface Comment {
    id?: number;
    communityId?: number;
    merchantId?: number;
    targetType?: string;
    targetId?: number;
    userId?: number;
    parentId?: number;
    replyToUserId?: number;
    content?: string;
    images?: string;
    likeCount?: number;
    auditStatus?: number;
    createTime?: string;
  }

  export interface CommentPageReqVO extends PageParam {
    targetType?: string;
    targetId?: number;
    userId?: number;
    auditStatus?: number;
    createTime?: string[];
  }
}

export function getCommentPage(params: CmtContentCommentApi.CommentPageReqVO) {
  return requestClient.get<PageResult<CmtContentCommentApi.Comment>>(
    '/cmt/content-comment/page',
    { params },
  );
}

export function getComment(id: number) {
  return requestClient.get<CmtContentCommentApi.Comment>(
    `/cmt/content-comment/get?id=${id}`,
  );
}

export function createComment(data: CmtContentCommentApi.Comment) {
  return requestClient.post('/cmt/content-comment/create', data);
}

export function updateComment(data: CmtContentCommentApi.Comment) {
  return requestClient.put('/cmt/content-comment/update', data);
}

export function deleteComment(id: number) {
  return requestClient.delete(`/cmt/content-comment/delete?id=${id}`);
}

export function deleteCommentList(ids: number[]) {
  return requestClient.delete(
    `/cmt/content-comment/delete-list?ids=${ids.join(',')}`,
  );
}

export function exportComment(params: CmtContentCommentApi.CommentPageReqVO) {
  return requestClient.download('/cmt/content-comment/export-excel', { params });
}

/** 获取评论选项列表(用于下拉选择) */
export function getCommentOptions() {
  return requestClient.get<PageResult<CmtContentCommentApi.Comment>>(
    '/cmt/content-comment/page',
    { params: { pageNo: -1, pageSize: 10 } },
  );
}
